﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HttpPackage;

namespace HTMLPackage
{
    class PageRetriever
    {
        Uri uri;
        HttpTcpClient client;

        public PageRetriever(Uri uri)
        {
            this.uri = uri;
            this.client = new HttpTcpClient();
        }

        public string GetPage()
        {
            // Open connection to the host
            client.Open(uri.Host);
            
            // Construct request for webpage
            string reqString = "GET " + uri.LocalPath + " HTTP/1.1\r\n";
            reqString += "Host:" + uri.Host + "\r\n\r\n";

            // Send request to server
            client.Send(reqString);

            // Read response from server
            string responseData = client.Receive();

            // Close connection to server
            client.Close();

            // Return the response
            return responseData;
        }
    }
}
